<template>
  <a-modal width="1000px" v-model:open="open" title="查看试题" cancelText="上一题" okText="下一题" @ok="next" @onCancel="prev">
    <template #footer>
      <a-button key="back" @click="prev">上一题</a-button>
      <a-button key="submit" type="primary" @click="next">下一题</a-button>
    </template>
    <a-carousel class="carousel" ref="carousel">
      <div v-for="(item, index) in examList" :key="item.id">
        <div class="type-one">
          <div class="name">{{ index + 1 }}、 {{ item?.question_name }}</div>
          <img v-if="item.question_type === 1" :src="item.question_url" alt="" class="question-img">
          <div class="select-list">
            <div class="item">
              <a-radio-group :value="answerToSelect[item.correct_answer]">
                <a-space :size="16" wrap>
                  <a-radio value="question_select_one">
                    <div class="radio-c">
                      <span>A、</span>
                      <img v-if="item.question_type === 0" :src="item.question_select_one" alt="" />
                      <span v-else>{{ item?.question_select_one }}</span>
                    </div>
                  </a-radio>
                  <a-radio value="question_select_two">
                    <div class="radio-c">
                      <span>B、</span>
                      <img v-if="item.question_type === 0" :src="item.question_select_two" alt="" />
                      <span v-else>{{ item?.question_select_two }}</span>
                    </div>
                  </a-radio>
                  <a-radio value="question_select_three">
                    <div class="radio-c">
                      <span>C、</span>
                      <img v-if="item.question_type === 0" :src="item.question_select_three" alt="" />
                      <span v-else>{{ item?.question_select_three }}</span>
                    </div>
                  </a-radio>
                  <a-radio value="question_select_four">
                    <div class="radio-c">
                      <span>D、</span>
                      <img v-if="item.question_type === 0" :src="item.question_select_four" alt="" />
                      <span v-else>{{ item?.question_select_four }}</span>
                    </div>
                  </a-radio>
                </a-space>
              </a-radio-group>
            </div>
          </div>
        </div>
      </div>
    </a-carousel>
  </a-modal>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { fetchExamPaperDetailQuery } from '@/api/exam'

const open = ref(false)
const answerToSelect: any = {
  'A': 'question_select_one',
  'B': 'question_select_two',
  'C': 'question_select_three',
  'D': 'question_select_four',
}
const openModal = (record: any) => {
  getExamList(record.id)
  open.value = true
}

const carousel = ref()
const position = ref(0)
const prev = () => {
  if (position.value === 0) return
  position.value -= 1
  carousel.value.goTo(position.value)
}
const next = () => {
  if (position.value >= examList.value.length - 1) return
  position.value += 1
  carousel.value.goTo(position.value)
}

const examList = ref<any[]>([])
const selectArr = ref<any[]>([])
const getExamList = async (id: string) => {
  const res = await fetchExamPaperDetailQuery({
    conditions: [
      {
        key: ' exam_paper_id',
        operator: 'eq',
        value: id
      }
    ]
  })
  examList.value = res.data.data
  selectArr.value = examList.value.map(() => void 0)
  carousel.value.goTo(0, true)
}

defineExpose({ openModal })
</script>

<style scoped lang="scss">


  .carousel {
    :deep(.slick-slide) {
      height: auto;
      overflow: hidden;
    }

    :deep(.slick-dots) {
      display: none !important;
    }
  }

  .type-one {
    //padding: 40px 56px 0;

    .question-img {
      //width: 300px;
      height: 300px;
      margin-bottom: 16px;
    }

    .select-list {
      min-height: 88px;

      .item {
        height: auto;
      }
    }

    .name {
      font-size: 20px;
      font-weight: bold;
      color: #000000;
      line-height: 44px;
      margin-bottom: 30px;
    }
  }

  .radio-c {
    display: flex;
    align-items: center;

    img {
      width: 88px;
      height: 88px;
    }
  }

</style>
